{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>用户组{:lang('list')}</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        <a href="{:url('add')}" class="layui-btn layui-btn-small">添加用户组</a>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="action">
	
    <a href="{:url('access')}?id={{d.id}}" class="layui-btn layui-btn-xs layui-btn-normal">配置规则</a>
    
	<a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-warm layui-btn-xs">{:lang('edit')}</a>
    {{# if(d.group_id==1){ }}
	<a class="layui-btn layui-btn-xs layui-btn-disabled">{:lang('del')}</a>
	{{# }else{  }}
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
	{{# } }}
</script>
<!--调整状态-->
<script type="text/html" id="status">
	{{# if(d.group_id==1){ }}
        <input type="checkbox" disabled name="is_open" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('enabled')}|{:lang('disabled')}" lay-filter="status" checked>
    {{# }else{  }}
        <input type="checkbox" name="is_open" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('enabled')}|{:lang('disabled')}" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
    {{# } }}
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
            elem: '#list'
            ,url: '{:url("index")}',
            method:'post',
            cols: [[
                {field:'id', title: '{:lang("id")}',align:'center', width:80,fixed: true,sort: true},
                {field:'title', title: '用户组名',align:'center', width:180},
                {field:'add_time', title: '{:lang("add_time")}',align:'center', width:200,sort: true},
				{field:'edit_time', title: '{:lang("edit_time")}',align:'center', width:200,sort: true},
                {field:'status',width:150,title: '{:lang("status")}',align:'center',toolbar:'#status'},
				{width:260,title: '{:lang("action")}',align:'center',toolbar:'#action'}
            ]]
        });
		form.on('switch(status)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post('{:url("status")}',{'id':id,'status':status},function (res) {

                layer.close(loading);
                if (res.errorCode == 8888) {
						layer.msg(res.msg,{time:1000,icon:1});
						//tableIn.reload();
                    }else{
                       layer.msg(res.msg,{time:1000,icon:2},function(){
							location.href = res.url;
							});
                        return false;
                    }

            })
        });
		
        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除该用户组吗！', function(index){
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                    $.post("{:url('del')}",{'id':data.id},function(res){
                        layer.close(loading);
                        layer.close(index);
                        if(res.errorCode==8888){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2},function(){
                                location.href = res.url;
                            });
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>